var app = new Vue({
	el: '#app',
	data: {
		host:globalData.constParam.url.baseUrl+'/',
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
		product_detail:{},
		src:'',
		Video:'', //视频地址
		url:{
			getMoney_Intelligent:'/api/appfun/GetMoney_Intelligent', //海外保单计划书，获取保单价格
			genOrder:"/api/Order/GenOrder", //获取订单号   RequestParas={'CargoName':'人寿保障M1','CargoNo':'03d9080f-8034-4b61-b0a6-4fde6ef89139','CargoCount':'1','Money':'5.00','Remark':'计划书','OrderType':'2'}
			getSimilarProducts:'/api/Product/GetSimilarProducts', //同类比较
			visitProduct:'/api/Product/VisitProduct', //访问记录
		},
		detail_show:false , //同类产品
		list_info:[], //同类产品列表
	},
	mounted: function() {
		var that = this;
		console.log(this.product_detail)
		globalData.getTempToken(function(){			
			//隐藏loading
			$('.loading').hide()
			console.log(globalData.utils.getUrl())
			if(globalData.utils.getUrl() && globalData.utils.getUrl().ProductID){
				globalData.ajaxPost('/api/Product/GetProductByID',{ID:globalData.utils.getUrl().ProductID},function(res) {
					if(res.suc){
						console.log(res.data)
						globalData.setStorage('product_detail', res.data)
						if(globalData.getStorage('product_detail')){
							console.log(globalData.getStorage('product_detail'))
							that.product_detail = globalData.getStorage('product_detail')
							that.src = that.product_detail.ProductIntroduction
							that.Video = that.product_detail.Video
						}
					}
				})
			}else{
				if(globalData.getStorage('product_detail')){
					console.log(globalData.getStorage('product_detail'))
					that.product_detail = globalData.getStorage('product_detail')
					that.src = that.product_detail.ProductIntroduction
					that.Video = that.product_detail.Video
				}
			}
			
//			计算pdf高度
//			that.change_style()
			$(document).on('click',function(){
				console.log(document.getElementById("my_video"))
				document.getElementById("my_video").pause()
			})
			$('#video').click(function(event){
				event.stopPropagation()
				var myVideo = document.getElementById("my_video");	
				console.log(myVideo)
				if(myVideo.paused){
					myVideo.play();
				}else{
					myVideo.pause();
				}
			})
		})		
	},
	methods: {
		reset:function(){
			
		},
		change_style:function(){
			console.log($('html').height())
			var h = $('html').height() - $('.my_header').height() - $('footer').height() -2 + 'px'
			$('.pdf').css({
				'height':h
			})
		},
		introduce:function(){   //查看详情ppt
			var item = this.product_detail
			console.log(item)			
			//详细资料
			if(!item.ProductDetail){
				$('#alert').modal()
				$('#alert p').text('暂无内容')
				return;
			}			
			if(item.IsNotFree && !item.IsPptPay){				
				var data = {
					'ModelID':globalData.getStorage('modelID'),
					'ConfigKey':'Tip_VisitProductPowerPointBeforeVip'
				} 
				
				globalData.getTips(data.ConfigKey,data.ModelID, function(res) {
					var p = res.data; 
					if(globalData.userInfo.IsVip==1){
						p = p.substring(0,p.indexOf('金币')+2);
					}
					$('#pay_detail p').text(p);
					$('#pay_detail').modal();
				})				
			}else{
				globalData.utils.setUrl("product_detail.html", null)
			}
		},
		playvideo:function(){
			var item = this.product_detail
			console.log(item)			
			if(globalData.userInfo.IsVip==0){
				$("#not_sign").modal()
				$('#not_sign p').text('尊敬的用户，您目前的身份为【注册用户】,尚无权限观看本项目的信息，请在个人中心中点击"签约用户"并上传证件照，通过审核后，您将成为【签约用户】且享有观看项目信息权限')
				return;
			}else if(globalData.userInfo.IsVip==3){
				$("#alert").modal()
				$("#alert p").text('您的签约资料已提交，正在审核中，请耐心等待')
				return
			}else if(globalData.userInfo.IsVip==2){
				$("#alert").modal()
				$("#alert p").text('您的签约资料审核未通过，请到个人中心重新提交签约资料！')
				return
			}
			if(!item.Video){
				$('#alert').modal()
				$('#alert p').text('敬请期待')
				return;
			}
			if(item.IsNotFree && !item.IsVideoPay){
				var data = {
					'ModelID':globalData.getStorage('modelID'),
					'ConfigKey':'Tip_SpentCoinsVisitProductVideo'
				}
				globalData.ajaxPost("/api/AppFun/GetTips", data, function(res) {
					console.log(res)
					$('#pay_video p').text(res.data)
					$('#pay_video').modal()		
					globalData.setStorage('product_item',item)
				})
				return;
			}		
			$('#video').modal()
			var myVideo = document.getElementById("my_video");			
			myVideo.play();
		},
		go_signed:function(){ //前往签约界面
			globalData.utils.setUrl('my_center.html',{type:5})
		},
		getSimilarProducts:function(){
			var that = this;
			var data = {
				Device:4,
				ID:that.product_detail.ID
			}
			globalData.ajaxPost(that.url.getSimilarProducts, data, function(res) {
				console.log(res)
				if(res.suc){
					globalData.utils.scrool_top()
					that.list_info = res.data
					that.detail_show = true;
				}
			})			
		},
		pay_product_detail:function(){
			//获取价格
			var price = 0
			var that = this
			globalData.ajaxPost("/api/Product/GetProductPrices",{'ModelID':globalData.getStorage('modelID')}, function(res) {
				console.log(res)					
				price = res.data[0].Price	
				//付钱
				var product_item = that.product_detail
				console.log(product_item)
				var data = {
					    'CargoName': product_item.ProductName,
					    'CargoNo': product_item.ProductNo,
					    'CargoCount': '1',
					    'Money': price,
					    'Remark': '产品PPT支付|'+ product_item.ID +'|',
					    'OrderType': '6'
				}
				globalData.ajaxPost("/api/Order/GenOrder",data, function(res) {
					console.log(res)
					if(res.suc){
						product_item.IsPptPay = true;					
						globalData.setStorage('product_detail',product_item)
						that.introduce()
					}else{
						$("#alert").modal()
						$("#alert p").text(res.msg)
					}
							
				})
			})
		},
		pay_video:function(){   //video
			//获取价格
			var price = 0
			var that = this
			globalData.ajaxPost("/api/Product/GetProductPrices",{'ModelID':globalData.getStorage('modelID')}, function(res) {
				console.log(res)					
				price = res.data[1].Price	
				//付钱
				var product_item = that.product_detail
				var data = {
					    'CargoName': product_item.ProductName,
					    'CargoNo': product_item.ProductNo,
					    'CargoCount': '1',
					    'Money': price,
					    'Remark': '产品视频支付|'+ product_item.ID +'|',
					    'OrderType': '5'
				}
				globalData.ajaxPost("/api/Order/GenOrder",data, function(res) {
					console.log(res)
					product_item.IsVideoPay = true;					
					globalData.setStorage('product_detail',product_item)
					that.playvideo()
//					$("#alert").modal()
//					$("#alert p").text(res.data.MsgContent)
//					$("#alert button").one("click",function(){
//						window.location.reload()
//					})				
				})
			})
		},
		go_singed:function(){
			globalData.utils.setUrl("my_center.html",{type:5})
		},
		hide: function() {
			this.detail_show = false
		},
		go_other_product: function(item) {
			globalData.setStorage('product_detail', item)
			globalData.utils.setUrl("product_intro.html", null)			
		},
		go_plan_book:function(){
			if(globalData.userInfo.IsVip==0){
				$("#not_sign").modal()
				$('#not_sign p').text('尊敬的用户，您目前的身份为【注册用户】,尚无权限观看本项目的信息，请在个人中心中点击"签约用户"并上传证件照，通过审核后，您将成为【签约用户】且享有观看项目信息权限')
				return;
			}else if(globalData.userInfo.IsVip==3){
				$("#alert").modal()
				$("#alert p").text('您的签约资料已提交，正在审核中，请耐心等待')
				return
			}else if(globalData.userInfo.IsVip==2){
				$("#alert").modal()
				$("#alert p").text('您的签约资料审核未通过，请到个人中心重新提交签约资料！')
				return
			}
			globalData.utils.setUrl('plan_book.html',null,true)
		}
	},
	filters:{
		
	}
})